<template>
	<!-- 废弃页面暂时用不着 -->
	<view class="">
		<view :class="data.status == 1 ? 'box-top' : 'box-tops'">
			{{ data.status_text }}
		</view>
		<view class="cord">

			<h5 class="bttext" style="margin: 16rpx 0rpx;">房屋信息</h5>

			<view class="textList">
				<view class="textListz">房屋地址</view>
				<view class="textListy">{{ data.house_address }}</view>
			</view>
			<view class="textList">
				<view class="textListz">房间</view>
				<view class="textListy">{{data.room_name}}</view>
			</view>
		</view>

		<view class="cord">
			<h5 class="bttext" style="margin: 16rpx 0rpx;">租期信息</h5>
			<view class="textList">
				<view class="textListz">租期开始时间</view>
				<view class="textListy">{{ data.start_time }}</view>
			</view>
			<view class="textList">
				<view class="textListz">租期截至时间</view>
				<view class="textListy">{{ data.end_time }}</view>
			</view>
		</view>

		<view class="cord">
			<h5 class="bttext" style="margin: 16rpx 0rpx;">租金与押金</h5>

			<view class="textList">
				<view class="textListz">租金</view>
				<view class="textListy">{{ data.money_zu }}元/月</view>
			</view>
			<view class="textList">
				<view class="textListz">押金方式</view>
				<view class="textListy">{{ data.ya_type_text }}</view>
			</view>
			<view class="textList">
				<view class="textListz">押金金额</view>
				<view class="textListy">{{ data.money_ya }}</view>
			</view>
		</view>

		<!-- <view class="cord">
			<view class="" style="display: flex; justify-content: space-between; align-items: center;">

				<h5 class="bttext" style="margin: 16rpx 0rpx;">合同附件</h5>
				<u-switch v-model="value" @change="change" size="20" disabled style="margin-right: 10rpx;"></u-switch>
			</view>
			<view class="annex">
				<view class="annexbox">
					<image style="width: 30rpx; height: 30rpx;" src="../../static/uploadImg/uploadFile.png" mode="">
					</image>
					<span style="margin-left: 15rpx;font-size: 25rpx;">房屋凭租合同</span>
				</view>
				<u-icon name="arrow-right" color="#000" size="18"></u-icon>
			</view>
		</view> -->

		<view class="cord">
			<h5 class="bttext" style="margin: 16rpx 0rpx;">图片</h5>
			<view class="bttextimg">
				<view class="bttextimgbox" v-for="i in data.photo" @click="previewImage(i)">
					<image style="width: 150rpx; height: 150rpx;" :src="i" mode=""></image>
				</view>


			</view>
		</view>

		<!-- 按钮 -->
		<view class="submitboxbuttons"></view>
		<!-- <view class="submitboxbutton" @click="downloadPDF">
			<view class="submitbox">
				查看附件
			</view>
		</view> -->
	</view>
</template>

<script>
	import {
		contractInfo
	} from '@/api/landlord.js'
	export default {
		data() {
			return {
				data: {},
				value: false,
			};
		},
		onLoad(options) {

			if (options.id) {

				this.init(options.id)
			}
		},
		methods: {
			init(e) {
				contractInfo({
					id: e
				}).then(res => {
					console.log(res.data.data);
					this.data = res.data.data
				})
			},
			previewImage(photoImg) {
				let imgsArray = [];
				imgsArray[0] = photoImg;
				uni.previewImage({
					current: 0,
					urls: imgsArray
				});
			},
			downloadPDF() {

				console.log(this.data);
				if (this.data.attachment.length == 0) {
					uni.showToast({
						title: '暂无附件',
						icon: 'none'
					});
					return
				}

				const pdfUrl = this.data.attachment[0]; // 替换为实际的 PDF 文件 URL
				uni.downloadFile({
					url: pdfUrl,
					success: (res) => {
						if (res.statusCode === 200) {
							uni.saveFile({
								tempFilePath: res.tempFilePath,
								success: (saveRes) => {
									uni.showToast({
										title: '下载成功',
										icon: 'success'
									});
									console.log('保存路径：', saveRes.savedFilePath);
								},
								fail: (err) => {
									uni.showToast({
										title: '保存失败',
										icon: 'none'
									});
									console.error('保存失败：', err);
								}
							});
						} else {
							uni.showToast({
								title: '下载失败',
								icon: 'none'
							});
							console.error('下载失败，状态码：', res.statusCode);
						}
					},
					fail: (err) => {
						uni.showToast({
							title: '下载失败',
							icon: 'none'
						});
						console.error('下载失败：', err);
					}
				});
			},
			change() {

			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			jump(path, parmas) {
				console.log(path);
				uni.navigateTo({
					url: path
				});
				// this.$Router.push({
				// 	path: path,
				// 	query: parmas
				// });
			},
		}
	};
</script>

<style lang="scss" scoped>
	.annex {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #feede5;
		box-sizing: border-box;
		padding: 15rpx;
		height: 80rpx;
		border-radius: 20rpx;

		.annexbox {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}

	.bttextimg {
		display: flex;
		flex-wrap: wrap;

		.bttextimgbox {
			// border: 1rpx solid red;
			margin: 8rpx;
			width: 150rpx;
			height: 150rpx;
			border-radius: 20rpx;
			overflow: hidden;
		}
	}

	.submitboxbuttons {
		height: 120rpx;
	}

	.submitboxbutton {
		position: fixed;
		bottom: 0rpx;
		left: 0;
		width: 100%;
		height: 120rpx;
		background-color: #fff;
	}

	.submitbox {
		position: fixed;
		bottom: 10rpx;
		left: 50%;
		width: 96%;
		margin: 0 auto;
		border-radius: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100rpx;
		margin-left: -48%;
		color: #fff;
		background-color: #fe4f04;
	}

	.bttext {
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #2A0C00;
	}

	.textList {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 80rpx;
		font-size: 25rpx;

		.textListz {
			font-size: 25rpx;
			color: #a4a4a4;
		}
	}

	.cord {
		box-sizing: border-box;
		width: 95%;
		margin: 30rpx auto;
		box-sizing: border-box;
		padding: 40rpx;
		background: #fff;
		border-radius: 15rpx;
	}

	.box-top {
		width: 100%;
		height: 80rpx;
		background-color: #81b336;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>